home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 172 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Problem with THIS
  5. Date: 2 Jan 1996 13:50:48 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Distribution: world
  8. Message-ID: <4cbd7o$kst@dawn.mmm.com>
  9. References: <4bpdlf$e8d@bigboote.WPI.EDU>
  10. Reply-To: kjhopps@mmm.com
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Alexander Schelkin (shura@cs.wpi.edu) wrote:
  14.  
  15. > I need your help.
  16.  
  17. > I am writing expression classes. I have the base class Expression
  18. > and derived classes SumExpression, MultiplicationExpresssion, 
  19. > SquareExpression, etc.
  20.  
  21. > I would like to have something like that:
  22.  
  23. > Expression* expr, *expr2;
  24. > expr = new Expression ("a + b");
  25. > expr2 = new Expression ("(a+b)**");
  26.  
  27. One approach would be to use the envelope/letter idiom.  The Expression
  28. class could be a container that holds a pointer to the "real" expression
  29. object.  Using this approach you might end up with one class hierarchy
  30. for the expressions and a single class for the envelope.  I could see
  31. an expression base class with a virtual "evaluate" member, a derivative
  32. "UnaryExpression" and a derivative "BinaryExpression," etc.
  33.  
  34. Another idea would be to separate the parsing of expressions from the
  35. expressions altogether.  Then instead of having an envelope class you
  36. could just write a stand-alone function that would parse a string and
  37. return an Expression pointer.
  38.  
  39. > Please send your messages to shura@cs.wpi.edu
  40.  
  41. People read your question because it was of interest.  They deserve to
  42. see responses.  Unless you promise to post a summary of responses, you'll
  43. have to read mine here.
  44. --
  45. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  46. 3M Company                      phone:  (612) 737-4643
  47. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  48. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  49.     But 3M speaks for me -- I did not write the following line:
  50.  
  51. Opinions expressed herein are my own and may not represent those of 3M.
  52.